// server.js
require('dotenv').config();
const app = require('./app');
const serverless = require('serverless-http');

const PORT = process.env.PORT || 3000;

if (process.env.NODE_ENV !== 'production') {
  // 仅在非生产环境（本地开发）启动服务器
  app.listen(PORT, () => {
    console.log(`服务器正在端口 ${PORT} 上运行`);
    console.log(`API文档可访问: http://localhost:${PORT}/api-docs`);
  });
}

// 为阿里云函数计算环境导出 handler
exports.handler = serverless(app);